"""
 Given a sorted integer array without duplicates, return the summary of its ranges.

For example, given [0,1,2,4,5,7], return ["0->2","4->5","7"]. 
"""

class Solution:
    # @param {integer[]} nums
    # @return {string[]}
    def summaryRanges(self, nums):
        """
        :type nums: []
        """
        if not nums:
            return []
        ans = []
        beg = nums[0]

        for i in range(1, len(nums)):
            if nums[i] != nums[i-1]+1:
                if beg == nums[i-1]:
                    ans.append(str(beg))
                else:
                    ans.append( '%d->%d' % (beg, nums[i-1] ))
                beg = nums[i]
        
        if beg == nums[-1]:
            ans.append(str(beg))
        else:
            ans.append( '%d->%d' % (beg, nums[-1]))

        return ans
        
if __name__ == '__main__':
    print Solution().summaryRanges([0, 1, 2, 4, 5, 7])

        
